
noi di "Mechanisms"

preserve 
********************************************
* TABLE 3: MECHANISMS
********************************************

*-------------------------
*PANEL A: Without any controls
*-------------------------

* Set 1: Standardized Test Scores
est clear
foreach var in $mechanisms {

	noi di "Mechanisms: `var' without controls"
	*1) Without any controls
	*local var "time_study_out"
	gen Baseline = `var'
	la var Baseline "Baseline"
	gen miss = missing(Baseline)
	replace Baseline = 0 if missing(Baseline)
	

	*Running the statistical inference
	qui ritest treatment _b[treatment], cluster(id_school) reps($reps): ///
	reg el_`var' treatment Baseline miss, vce(robust)
	matrix pvalues = r(p)
	gen temp = pvalues[1,1]

	qui eststo panela_`var': bootstrap, seed(2905) cl(id_school) reps($reps) nodots: qui reg el_`var' treatment Baseline miss
	*eststo: reg el_`var' treatment Baseline miss, vce(robust)
	qui test treatment 
	qui estadd scalar pvalreg = round(r(p),0.001)
	qui summ el_`var' if treatment == 0 & miss == 0
	qui estadd scalar mean = r(mean)
	qui estadd local ife = "No", replace
	qui estadd local sfe = "No", replace
	qui estadd local regtype = "OLS", replace
	qui estadd scalar rsq = e(r2)

	qui summ temp
	qui estadd scalar pvalri= r(mean)
	drop Baseline miss temp
}

*----------------------------------------
*PANEL B: With individual and school controls
*----------------------------------------
* Set 1: Level increases
* Set 1: Standardized Test Scores
foreach var in $mechanisms {

	noi di "Mechanisms: `var' with controls"
	*1) Without any controls
*	local var "readcode"
	gen Baseline = `var'
	la var Baseline "Baseline"
	gen miss = missing(Baseline)
	replace Baseline = 0 if missing(Baseline)
	

	*Running the statistical inference
	qui ritest treatment _b[treatment], cluster(id_school) reps($reps): ///
	reg el_`var' treatment Baseline miss $indcontrols $schcontrols, vce(robust)
	matrix pvalues = r(p)
	gen temp = pvalues[1,1]

	eststo panelb_`var': qui bootstrap, seed(2905) cl(id_school) reps($reps) nodots: qui reg el_`var' treatment Baseline miss $indcontrols $schcontrols
*	eststo: reg el_`var' treatment Baseline miss, vce(robust)
	qui test treatment 
	qui estadd scalar pvalreg = round(r(p),0.001)
	qui summ el_`var' if treatment == 0 & miss == 0
	qui estadd scalar mean = r(mean)
	qui estadd local ife = "Yes", replace
	qui estadd local sfe = "Yes", replace
	qui estadd local regtype = "OLS", replace
	qui estadd scalar rsq = e(r2)
	
	qui summ temp
	qui estadd scalar pvalri= r(mean)
	drop Baseline miss temp
}

# delimit ;
esttab  panela* using "$tables/Table3.tex", replace
keep(treatment Baseline)
cells(b(fmt(%5.2f) star) se(fmt(%5.2f) par))
starlevels(* .10 ** .05 *** .01) 
mgroups("Absenteeism" "Parent" "Tuition" "Self-Study", pattern(1 1 1 0 1 0)
span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) 
mtitle("Days/Week" "Support" "At least 1 day" "Days/Week" "At least 1 day" "Days/Week")
posthead("\midrule \multicolumn{7}{l}{\textit{\textbf{Panel A. Without individual and school controls}}} \\ \midrule")
postfoot("")
stats(pvalreg pvalri rsq, labels("p-val (OLS)" "p-val (RI)" "\midrule R2") ///
fmt(2 2 2)) ///
collabels(none) label booktabs nonotes
;

# delimit ;
esttab  panelb* using "$tables/Table3.tex", append
keep(treatment Baseline) ///
cells(b(fmt(%5.2f) star) se(fmt(%5.2f) par)) /// 
starlevels(* .10 ** .05 *** .01) ///
prehead("") ///
posthead("\midrule \multicolumn{7}{l}{\textit{\textbf{Panel B. With individual and school controls}}} \\ \midrule")
stats(pvalreg pvalri rsq N, labels("p-val (OLS)" "p-val (RI)" "\midrule R2" "N") ///
fmt(2 2 2 0)) ///
collabels(none) mlabels(none) nonumbers label booktabs nonotes nomtitles;
#delimit cr	


restore 